unit RelatorioSaldoCriditoCliente;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, UrelatorioBase, RLReport, DBCtrls, StdCtrls, CheckLst,
  RLPDFFilter, RLXLSFilter, RLFilters, RLHTMLFilter, RLDraftFilter, DB,
  DBTables, ExtCtrls, Buttons;

type
  TFRelatorioSaldoCriditoCliente = class(TFrelatorioBase)
    DSCliente: TDataSource;
    Label10: TLabel;
    CLBEmpresas: TCheckListBox;
    Label6: TLabel;
    DBLCBCliente: TDBLookupComboBox;
    RLBand2: TRLBand;
    RLBand3: TRLBand;
    RLLabel1: TRLLabel;
    RLLabel2: TRLLabel;
    RLLabel3: TRLLabel;
    RLDBText2: TRLDBText;
    RLDBText3: TRLDBText;
    RLDBText4: TRLDBText;
    RLBand4: TRLBand;
    RLDBResult1: TRLDBResult;
    RLLabel4: TRLLabel;
    procedure btnPesquisarClick(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure DBLCBClienteKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  FRelatorioSaldoCriditoCliente: TFRelatorioSaldoCriditoCliente;

implementation

uses UDMGeral, UDmGestao, UGeral;

{$R *.dfm}

procedure TFRelatorioSaldoCriditoCliente.btnPesquisarClick(Sender: TObject);
const
  ctPesquisa =
    'SELECT'#10+
    '  CLIENTE.CLI_CODIGO,'#10+
    '  CLIENTE.CLI_RAZAO,'#10+
    '  CLIENTE.CLI_VALOR_CREDITO'#10+
    'FROM'#10+
    '  CLIENTE'#10+
    'WHERE'#10+
    '  (CLIENTE.CLI_VALOR_CREDITO > 0)AND'#10+
    '  (CLIENTE.EXCLUIDO <> ''S'' OR CLIENTE.EXCLUIDO IS NULL)%s';

var
  Filtro : String;

begin
  if DBLCBCliente.KeyValue <> null then
    Filtro := 'AND(CLI_CODIGO = ' + VarToStr(DBLCBCliente.KeyValue) + ')';

  QPesquisa.Close;
  QPesquisa.SQL.Clear;
  QPesquisa.SQL.Add(Format(ctPesquisa, [Filtro]));
  QPesquisa.Open;

  TCurrencyField(QPesquisa.FieldByName('CLI_VALOR_CREDITO')).DisplayFormat := '#,##0.00';

  inherited;

end;

procedure TFRelatorioSaldoCriditoCliente.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  inherited;
  FRelatorioSaldoCriditoCliente.Release;
  FRelatorioSaldoCriditoCliente := Nil;
end;

procedure TFRelatorioSaldoCriditoCliente.DBLCBClienteKeyDown(
  Sender: TObject; var Key: Word; Shift: TShiftState);
begin
  inherited;
  fun_dblookup(Key, Shift, DBLCBCliente);
end;

end.
